package com.ymatou.iapi.godmch.testcase;

import java.util.HashMap;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.setBuyerCsBean;
import com.ymatou.iapi.godmch.parameter.setShareTypeBean;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.setBuyerCsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.mch_info;
import com.ymttest.database.sqlwapper.godmch.mch_infoWapper;
import com.ymttest.utils.TestDataManager;
/**
*设置商户买家端客服
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_setBuyerCs{
	private static setBuyerCsBean bean;
	private static setBuyerCsCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置商户买家端客服");
	}

	@Before
	public void caseUp() {
		bean=new setBuyerCsBean();
		call=new setBuyerCsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void check_verify(Integer mchId_channl) throws InterruptedException
	{
		//验证
		mch_infoWapper mchinfoWapper=new mch_infoWapper();
		HashMap<String,Object> map=new HashMap();
		map.put("mchId", mchId_channl);
	    mch_info act_info=mchinfoWapper.selectby(map).get(0);
	    
		Logger.verifyEquals("200", call.getStatus1(), "验证status");
		Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证msg");
		Logger.verifyEquals(bean.getEnabled(), act_info.getBuyerCsEnabled(), "验证数据库中的BuyerCsEnabled与设置的一致");
		Logger.verifyEquals(bean.getWechat()==null?"":bean.getWechat(), act_info.getBuyerCsWechat(), "验证数据库中的BuyerCsWechat与设置的微信号一致");
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setBuyerCs_001() {
		Logger.start(true,"正例-设置商户买家端客服-小程序-设置客服微信号-返回成功");
		try {
			//创建渠道
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			//设置分享类型
			setShareTypeBean setShareTypeBean=GodmchManageCallService.initsetShareTypeV2(mchId_channl);
			setShareTypeBean.setMchShareType(1);//1：小程序 2：H5 3：独立小程序  4：独立h5  5：继承版小程序
			GodmchManageCallService.setShareTypeV2Call(setShareTypeBean);
			
			bean.setMchId(mchId_channl);
			bean.setEnabled(true);
			bean.setWechat("test_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			check_verify(mchId_channl);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setBuyerCs_001_1() {
		Logger.start(true,"正例-设置商户买家端客服-小程序-关闭设置客服微信号-返回成功");
		try {
			//创建渠道
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			//设置分享类型
			setShareTypeBean setShareTypeBean=GodmchManageCallService.initsetShareTypeV2(mchId_channl);
			setShareTypeBean.setMchShareType(1);//1：小程序 2：H5 3：独立小程序  4：独立h5  5：继承版小程序
			GodmchManageCallService.setShareTypeV2Call(setShareTypeBean);
			
			bean.setMchId(mchId_channl);
			bean.setEnabled(true);
			bean.setWechat("test_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			bean.setEnabled(false);
			call.setData(bean);
			call.callService();		
			check_verify(mchId_channl);		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setBuyerCs_002() {
		Logger.start(true,"正例-设置商户买家端客服-小程序-不设置客服微信号-返回失败");
		try {
			//创建渠道
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			//设置分享类型
			setShareTypeBean setShareTypeBean=GodmchManageCallService.initsetShareTypeV2(mchId_channl);
			setShareTypeBean.setMchShareType(1);//1：小程序 2：H5 3：独立小程序  4：独立h5  5：继承版小程序
			GodmchManageCallService.setShareTypeV2Call(setShareTypeBean);
			
			bean.setMchId(mchId_channl);
			bean.setEnabled(true);
			//bean.setWechat("test_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	

			Logger.verifyEquals("5000", call.getStatus1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("客服微信号不能为空"), "验证msg");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setBuyerCs_003() {
		Logger.start(true,"正例-设置商户买家端客服-H5-设置客服微信号-返回成功");
		try {
			//创建渠道
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			//设置分享类型
			setShareTypeBean setShareTypeBean=GodmchManageCallService.initsetShareTypeV2(mchId_channl);
			setShareTypeBean.setMchShareType(2);//1：小程序 2：H5 3：独立小程序  4：独立h5  5：继承版小程序
			GodmchManageCallService.setShareTypeV2Call(setShareTypeBean);
			
			bean.setMchId(mchId_channl);
			bean.setEnabled(true);
			bean.setWechat("test_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			bean.setEnabled(false);
			call.setData(bean);
			call.callService();		
			check_verify(mchId_channl);			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setBuyerCs_004() {
		Logger.start(true,"正例-设置商户买家端客服-H5-不设置客服微信号-返回失败");
		try {
			//创建渠道
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			//设置分享类型
			setShareTypeBean setShareTypeBean=GodmchManageCallService.initsetShareTypeV2(mchId_channl);
			setShareTypeBean.setMchShareType(2);//1：小程序 2：H5 3：独立小程序  4：独立h5  5：继承版小程序
			GodmchManageCallService.setShareTypeV2Call(setShareTypeBean);
			
			bean.setMchId(mchId_channl);
			bean.setEnabled(true);
			//bean.setWechat("test_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	

			Logger.verifyEquals("5000", call.getStatus1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("客服微信号不能为空"), "验证msg");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setBuyerCs_005() {
		Logger.start(true,"正例-设置商户买家端客服-独立小程序-设置客服微信号-返回成功");
		try {
			//创建渠道
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			//设置分享类型
			setShareTypeBean setShareTypeBean=GodmchManageCallService.initsetShareTypeV2(mchId_channl);
			setShareTypeBean.setMchShareType(3);//1：小程序 2：H5 3：独立小程序  4：独立h5  5：继承版小程序
			GodmchManageCallService.setShareTypeV2Call(setShareTypeBean);
			
			bean.setMchId(mchId_channl);
			bean.setEnabled(true);
			bean.setWechat("test_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			bean.setEnabled(false);
			call.setData(bean);
			call.callService();		
			check_verify(mchId_channl);				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setBuyerCs_006() {
		Logger.start(true,"正例-设置商户买家端客服-独立小程序-不设置客服微信号-返回成功(独立小程序可以不设置微信号)");
		try {
			//创建渠道
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			//设置分享类型
			setShareTypeBean setShareTypeBean=GodmchManageCallService.initsetShareTypeV2(mchId_channl);
			setShareTypeBean.setMchShareType(3);//1：小程序 2：H5 3：独立小程序  4：独立h5  5：继承版小程序
			setShareTypeBean.setPayMode(5);
			GodmchManageCallService.setShareTypeV2Call(setShareTypeBean);
			
			bean.setMchId(mchId_channl);
			bean.setEnabled(true);
			//bean.setWechat("test_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	

			check_verify(mchId_channl);			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setBuyerCs_007() {
		Logger.start(true,"正例-设置商户买家端客服-独立h5-设置客服微信号-返回成功");
		try {
			//创建渠道
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			//设置分享类型
			setShareTypeBean setShareTypeBean=GodmchManageCallService.initsetShareTypeV2(mchId_channl);
			setShareTypeBean.setMchShareType(4);//1：小程序 2：H5 3：独立小程序  4：独立h5  5：继承版小程序
			GodmchManageCallService.setShareTypeV2Call(setShareTypeBean);
			
			bean.setMchId(mchId_channl);
			bean.setEnabled(true);
			bean.setWechat("test_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			bean.setEnabled(false);
			call.setData(bean);
			call.callService();		

			check_verify(mchId_channl);		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setBuyerCs_008() {
		Logger.start(true,"正例-设置商户买家端客服-独立h5-不设置客服微信号-返回失败");
		try {
			//创建渠道
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			//设置分享类型
			setShareTypeBean setShareTypeBean=GodmchManageCallService.initsetShareTypeV2(mchId_channl);
			setShareTypeBean.setMchShareType(4);//1：小程序 2：H5 3：独立小程序  4：独立h5  5：继承版小程序
			GodmchManageCallService.setShareTypeV2Call(setShareTypeBean);
			
			bean.setMchId(mchId_channl);
			bean.setEnabled(true);
			//bean.setWechat("test_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	

			Logger.verifyEquals("5000", call.getStatus1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("客服微信号不能为空"), "验证msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setBuyerCs_009() {
		Logger.start(true,"正例-设置商户买家端客服-继承版小程序-设置客服微信号-返回成功");
		try {
			//创建渠道
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			//设置分享类型
			setShareTypeBean setShareTypeBean=GodmchManageCallService.initsetShareTypeV2(mchId_channl);
			setShareTypeBean.setMchShareType(5);//1：小程序 2：H5 3：独立小程序  4：独立h5  5：继承版小程序
			GodmchManageCallService.setShareTypeV2Call(setShareTypeBean);
			
			bean.setMchId(mchId_channl);
			bean.setEnabled(true);
			bean.setWechat("test_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			bean.setEnabled(false);
			call.setData(bean);
			call.callService();		

			check_verify(mchId_channl);				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setBuyerCs_010() {
		Logger.start(true,"正例-设置非独立商户 买家端客服-继承版小程序-不设置客服微信号-返回成功");
		try {
			//创建渠道
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);

			
			bean.setMchId(createIndepMchCall.getmchId());
			bean.setEnabled(true);
			//bean.setWechat("test_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	

			check_verify(bean.getMchId());				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}